package jeme.lang;

/**
 *
 *
 * @author Erik Silkensen (silkense@colorado.edu)
 * @version Jan 10, 2009
 */
public class SchemeBoolean extends SchemeObject
{
    /**
     * 
     */
    public static final SchemeBoolean TRUE = new SchemeBoolean(true);

    /**
     * 
     */
    public static final SchemeBoolean FALSE = new SchemeBoolean(false);
    
    /**
     * 
     */
    private static final String TRUE_REP = "#t";
    
    /**
     * 
     */
    private static final String FALSE_REP = "#f";
    
    public static final SchemeBoolean parseBoolean(SchemeString value)
    {
        return parseBoolean(value.toString());
    }
    
    /**
     * Parses the value string into a <code>SchemeBoolean</code> object.  If the
     * string is equal (case insensitive) to <code>#t</code>, then 
     * <code>TRUE</code> is returned. Else, <code>FALSE</code> is returned.
     * 
     * @param value  a string representation of a <code>SchemeBoolean</code>
     * @return  the <code>SchemeBoolean</code> represented by the string value
     */
    public static final SchemeBoolean parseBoolean(String value)
    {    
        return value.toLowerCase().equals(TRUE_REP) ? TRUE : FALSE;
    }
    
    private boolean value;
    
    /**
     * 
     * @param value
     */
    private SchemeBoolean(boolean value)
    {
        this.value = value;
    }
    
    /**
     * 
     * @return
     */
    public boolean valueOf()
    {
        return value;
    }
    
    /*
     * (non-Javadoc)
     * @see jeme.lang.SchemeObject#toString()
     */
    public String toString()
    {
        return valueOf() ? TRUE_REP : FALSE_REP;
    }
}
